package com.framewiki.gpt.filter;

import com.cdkjframework.config.CustomConfig;
import com.framewiki.gpt.config.ChatConfiguration;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ProjectName: linkeddt-hyqtds
 * @Package: cn.linkeddt.hyqtds.web.sh.filter
 * @ClassName: WebConfigurer
 * @Description: java类作用描述
 * @Author: xiaLin
 * @Date: 2023/4/5 19:16
 * @Version: 1.0
 */
@Configuration
@RequiredArgsConstructor
public class WebConfigurer implements WebMvcConfigurer {

    /**
     * 配置
     */
    private final ChatConfiguration configuration;

    /**
     * 配置
     */
    private final CustomConfig customConfig;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor())
                // 表示拦截所有请求
                .addPathPatterns("/**")
                // 表示取消对特定路径的拦截
                .excludePathPatterns("/csrf")
                .excludePathPatterns("/dms/")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/swagger-ui.html")
                .excludePathPatterns("/swagger-resources/**");
    }

    @Bean
    public AuthorityInterceptor authenticationInterceptor() {
        return new AuthorityInterceptor(configuration, customConfig);
    }
}
